POV-Ray : Newsgroups : povray.newusers : Calculate the camera position automatic : Re: Calculate the camera position automatic Server Time
4 Nov 2024 12:58:54 EST (-0500)
  Re: Calculate the camera position automatic  
From: Phil Cook
Date: 10 Sep 2003 06:14:17
Message: <opru931zpaeybzwd@news.povray.org>
On Tue, 09 Sep 2003 12:45:31 +0100, Phil Cook <phi### [at] deckingdealscouk> 
wrote:


> <fr### [at] computermuseumfh-kielde> wrote:
>
>> Hi Phil and Florian!
>>
>> Because the camera's look-at is <.5,.5,.5>, a box{0,1} is exactly what
>> is needed, but unfortunately Phil's calculations are a bit wrong: they
>> only work if Minimum.x and Maximum.x have different sign or one of them
>> is zero. (Similar for .y, .z.) The correct formulas are
>>
>> #declare TotalX = Maximum.x-Minimum.x;
>> #declare TotalY = Maximum.y-Minimum.y;
>> #declare TotalZ = Maximum.z-Minimum.z;
>>
>> abs is not required.
>> The calculation of MaxLength can be simplified to
>>
>> #declare MaxLength = max(TotalX,TotalY,TotalZ);
>>
>> or, compressing all this into one statement:
>>
>> #declare MaxLength = max(
>> Maximum.x-Minimum.x,
>> Maximum.y-Minimum.y,
>> Maximum.z-Minimum.z );
>>
>>
>> The vector <-Minimum.x,-Minimum.y,-Minimum.z> is the same as -Minimum,
>> so positioning of the Object is done by
>>
>> object { Object translate -Minimum scale 1/MaxLength }
>>
>>
>> The spheres for indication of the bounds are more easily readable as
>>
>> union {
>> sphere{<0,0,0>,0.1}
>> sphere{<1,0,0>,0.1}
>> sphere{<0,1,0>,0.1}
>> sphere{<0,0,1>,0.1}
>> sphere{<1,1,0>,0.1}
>> sphere{<1,0,1>,0.1}
>> sphere{<0,1,1>,0.1}
>> sphere{<1,1,1>,0.1}
>> pigment {rgbt <0,1,0,0.5>} finish{ambient 0.4 diffuse 0.6}
>> }
>>
>>
>> So, aside from the errors with TotalX/Y/Z, Phil's code is correct.
>> But I agree with Florian that a box{-0.5,0.5} might be better because
>> the look_at would be 0 in this case which makes the placement of the
>> camera a bit easier: I prefer to define the position of the camera by
>> rotation (instead of absolute coordinates), which is easier with a
>> look_at of 0. For example:
>>
>> camera { location -Distance*z look_at 0 rotate <Elevation,Rotation,0> }
>>
>> Distance should be chosen in such a way that all points of the Object 
>> are
>> visible for arbitrary values of Elevation and Rotation. The maximum
>> distance from the origin of a point in a box{-0.5,0.5} is sqrt(3*0.5^2)
>> =sqrt(0.75). All the points with this distance from the origin lie on a
>> sphere{0,sqrt(0.75)}. If this sphere is completely visible, then the
>> Object also is completely visible regardless of rotations of the camera.
>> A bit of calculation reveals a neccessary Distance of sqrt(3.75)=1.9365
>> (or more, for example 2) for a standard camera.
>>
>> Sputnik
>>
>>
>>
>
> Thanks Florian and Sputnik for the pointers, I slapped myself on the head 
> when I looked at the the #declare for TotalX etc., I actually looked up 
> max but saw it was for floats and I was thinking in vectors at the time 
> duh!
> I actually placed the min_extent at the origin as I have had some strange 
> results in scaling objects away from it, as follows:
>
> //POVWin 3.5 file starts here
> camera{
> location <17,50,-100>
> look_at <17,25,0>
> }
>
> #declare unitdivider = union{
> box{0,<35,52-6,-2.3>}
> cylinder{<0,0,0>,<0,0,-2.3>, 6 scale <35/12,1,1> translate <35/2,52-6,0>}
> //cylinder{<0,0,0>,<0,0,-2.3>, 6 translate <35/2,52-6,0> scale 
> <35/12,1,1>}
> pigment{rgb <1,0,0>} finish{ambient 0.6 diffuse 0.4}
> }
>
> object{unitdivider}
> //POV file ends here
>
> If I translate then scale as per commented out line, the cylinder floats 
> to +x of the box. Shifting the 35/12 to y and z produces the same results 
> in the obvious directions.
>
> I've just tried the combined code from you and Florian, and that works 
> fine though, of course:).
>
> Am I doing something fundamentally stupid?
>
> --
> Phil
>
>

Well looks like I can answer my own question, after a bit of 
experimentation I think the following explains the scaling situation,

//original sphere
sphere{<1,1,1>, 1  pigment{rgbt <1,0,0,0.6>} finish{ambient 0.6 diffuse 
0.4}}
//centre of original sphere
sphere{<1,1,1>, 0.5  pigment{rgb <0,1,0>} finish{ambient 0.6 diffuse 0.4}}
//same sphere scaled
sphere{<1,1,1>, 1  pigment{rgbt <1,0,0,0.6>} finish{ambient 0.6 diffuse 
0.4} scale 2}
//center of new sphere
sphere{<2,2,2>, 0.5  pigment{rgb <0,0,1>} finish{ambient 0.6 diffuse 0.4}}

So
sphere{<1,1,1>,1 scale 2} is equivalent to a sphere{<2,2,2>,2}

cylinder{<1,1,1>,<1,3,1>, 1 scale 2} is a cylinder{<2,2,2>, <2,6,2>,2}
and
box{<1,1,1>,<3,3,3> scale 2} is a box{<2,2,2>,<6,6,6>}

which makes sense just multiple the vectors by the scale, it's a shame that 
the help file uses a 0 sphere as it's example, as this won't show any 
translation (0*any number =0).

This is probably well known and understood by POV-Ray writers more 
competent than myself, but it confused the heck out of me at first.

--
Phil

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.